<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>电子书城</title>
<link rel="stylesheet" href="css/main.css" type="text/css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery-1.8.3.js"></script>
<script type="text/javascript">
function add(sdss,id,pum,mum){
    var ss = "#"+"quantity"+sdss;
    var  t =$(ss)
    var  min="#"+"min"+sdss;
    var  add="#"+"add"+sdss;
    var  total="#"+"total"+sdss;
    var  jage="#"+"jage"+sdss;
    if(id==1){
    	if(parseInt(t.val())<mum){
    		t.val(parseInt(t.val())+1);    
    	    $("#min"+sdss).removeAttr("disabled"); 
    	    var zong=parseInt($("#zong").val());
            $("#zong1").html(zong+pum);
            $("#zong").val(zong+pum);
    	}else{    
            $("#min").attr("disabled","disabled")        //当$("#min")为1时，$("#min")不可读状态    
        }
    	$("#total").html($("#total").text+pum);
    	$(total).html(parseInt(t.val())*pum);
    	
    }else{
        if (parseInt(t.val())>1) {                     //判断数量值大于1时才可以减少    
             t.val(parseInt(t.val())-1)
             $("#min"+sdss).removeAttr("disabled");
             var zong=parseInt($("#zong").val());
             $("#zong1").html(zong-pum);
             $("#zong").val(zong-pum);
        }else{    
             $("#min").attr("disabled","disabled")        //当$("#min")为1时，$("#min")不可读状态    
       } 
    $(total).html(parseInt(t.val())*pum);
    }
}

	</script>
</head>

<body class="main">

	<jsp:include page="head.jsp" />

	<jsp:include page="menu_search.jsp" />


	<div id="divpagecontent">
		<table width="100%" border="0" cellspacing="0">
			<tr>

				<td><div style="text-align:right; margin:5px 10px 5px 0px">
						<a href="index.html">首页</a>&nbsp;&nbsp;&nbsp;&nbsp;&gt;&nbsp;&nbsp;&nbsp;&nbsp;购物车
					</div>

					<table cellspacing="0" class="infocontent">
						<tr>
							<td><img src="ad/page_ad.jpg" width="666" height="89" />
								<table width="100%" border="0" cellspacing="0">
									<tr>
										<td><img src="images/buy1.gif" width="635" height="38" />
										</td>
									</tr>
									<tr>
										<td>
											<table cellspacing="1" class="carttable">
												<tr>
													<td width="10%">序号</td>
													<td width="30%">商品名称</td>
													<td width="10%">价格</td>
													<td width="20%">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;数量</td>
													<td width="10%">库存</td>
													<td width="10%">小计</td>
													<td width="10%">取消</td>
												</tr>
											</table> 
												<table width="100%" border="0" cellspacing="0">
												
	<%
	int num=0;
	int nam=0;
	Cookie[] allCookie = request.getCookies();
    Cookie userCookie = null;
    if (allCookie != null) {
        for (Cookie c : allCookie) {
        	System.out.println(c.getName());
            if ("iop".equals(c.getName())) {
                userCookie = c; 
            }
        }
    }
    String [] p=null;
    if (userCookie!=null){
	
        int a=0;
		String str = userCookie.getValue();
		p = str.split("/");
        for(int i=0; i<p.length; i++){
        	String[] u = p[i].split("@");
        	num=num+(Integer.parseInt(u[0])*Integer.parseInt(u[3]));
        	nam=(Integer.parseInt(u[0])*Integer.parseInt(u[3]));
        		%>
												  <tr>
													<td width="10%"><%=a%></td>
													<td width="30%"><%=u[1]%></td>

														<td width="10%" id="jage<%=a%>"><%=u[0]%></td>
														<td width="20%">
														<input type="button" value='-'
															style="width:20px" id="min<%=a%>" onclick="add(<%=a%>,2,<%=u[0]%>,<%=u[2]%>)"> 
                                                             
															<input name="text" id="quantity<%=a%>" type="text"  value="<%=u[3]%>"
															style="width:40px;text-align:center" />
															<input
															type="button" value='+' style="width:20px" id="add<%=a%>" onclick="add(<%=a%>,1,<%=u[0]%>,<%=u[2]%>)">

														</td>
														<td width="10%" ><%=u[2]%></td>
														<td width="10%" id="total<%=a%>"><%=nam%></td>

														<td width="10%"><a href="#"
															style="color:#FF0000; font-weight:bold" >X</a></td>
													</tr>
													
    		<%
        	a++;
        }
    }
	%>
												</table>
												


											<table cellspacing="1" class="carttable">
												<tr>
													<td style="text-align:right; padding-right:40px;"><font
														style="color:#FF6600; font-weight:bold">合计:<input type="hidden" value="<%=num%>" id="zong" >
														<a  id="zong1"><%=num%></a>元</font>
													</td>
												</tr>
											</table>
											<div style="text-align:right; margin-top:10px">
												<a
													href="FunctionServlet?id=1&type=1"><img
													src="images/gwc_jx.gif" border="0" /> </a>

												&nbsp;&nbsp;&nbsp;&nbsp;<a
													href="order.jsp"><img
													src="images/gwc_buy.gif" border="0" /> </a>
											</div>
										</td>
									</tr>
								</table>
							</td>
						</tr>
					</table></td>
			</tr>
		</table>
	</div>
	<jsp:include page="foot.jsp" />


</body>
</html>
